import Vue from "vue";
import App from "./App/App.vue";
import router from "./router";
import store from "./store";

import { sync } from "vuex-router-sync";
sync(store, router);

import "./plugins/link-ui";
import "@/assets/styles/common.scss";
import "@/assets/styles/reset.css";

import "@/components";

import "@/svgIcon";
import { codeDate } from "@/utils/menucode";

import http from "@/api/api";

import "@/utils/loading";
import "@/utils/filter";
import "@/utils/directive";

import echarts from "echarts";
import VueECharts from "vue-echarts";
Vue.prototype.$echarts = echarts;
Vue.component("v-chart", VueECharts);

router.beforeEach(async (to, from, next) => {
    http.defaults.headers.common["menucode"] =
        (await codeDate(to.path)) || "ORGT0101_SYS_MODULE_HOME_PAGE_PROVINCE";
    next();
});

Vue.config.productionTip = false;

new Vue({
    router,
    store,
    render: (h) => h(App),
    mounted() {
        // 确保 Layui 在 Vue 实例创建后初始化
        this.$nextTick(() => {
            if (layui && layui.layer) {
                layui.use(["layer"], function () {
                    // console.log("Layui is ready");
                });
            }
        });
    },
}).$mount("#app");
